package util;

import java.util.HashMap;
import java.util.Map;

public class StateConverter {
	static Map<String, String> states = new HashMap<String, String>();
	static Map<String, String> caseInsensitiveStates = new HashMap<String, String>();

	static {
		states.put("Alabama", "AL");
		states.put("Alaska", "AK");
		states.put("Alberta", "AB");
		states.put("American Samoa", "AS");
		states.put("Arizona", "AZ");
		states.put("Arkansas", "AR");
		states.put("Armed Forces (AE)", "AE");
		states.put("Armed Forces Americas", "AA");
		states.put("Armed Forces Pacific", "AP");
		states.put("British Columbia", "BC");
		states.put("California", "CA");
		states.put("Colorado", "CO");
		states.put("Connecticut", "CT");
		states.put("Delaware", "DE");
		states.put("District Of Columbia", "DC");
		states.put("Florida", "FL");
		states.put("Georgia", "GA");
		states.put("Guam", "GU");
		states.put("Hawaii", "HI");
		states.put("Idaho", "ID");
		states.put("Illinois", "IL");
		states.put("Indiana", "IN");
		states.put("Iowa", "IA");
		states.put("Kansas", "KS");
		states.put("Kentucky", "KY");
		states.put("Louisiana", "LA");
		states.put("Maine", "ME");
		states.put("Manitoba", "MB");
		states.put("Maryland", "MD");
		states.put("Massachusetts", "MA");
		states.put("Michigan", "MI");
		states.put("Minnesota", "MN");
		states.put("Mississippi", "MS");
		states.put("Missouri", "MO");
		states.put("Montana", "MT");
		states.put("Nebraska", "NE");
		states.put("Nevada", "NV");
		states.put("New Brunswick", "NB");
		states.put("New Hampshire", "NH");
		states.put("New Jersey", "NJ");
		states.put("New Mexico", "NM");
		states.put("New York", "NY");
		states.put("Newfoundland", "NF");
		states.put("North Carolina", "NC");
		states.put("North Dakota", "ND");
		states.put("Northwest Territories", "NT");
		states.put("Nova Scotia", "NS");
		states.put("Nunavut", "NU");
		states.put("Ohio", "OH");
		states.put("Oklahoma", "OK");
		states.put("Ontario", "ON");
		states.put("Oregon", "OR");
		states.put("Pennsylvania", "PA");
		states.put("Prince Edward Island", "PE");
		states.put("Puerto Rico", "PR");
		states.put("Quebec", "PQ");
		states.put("Rhode Island", "RI");
		states.put("Saskatchewan", "SK");
		states.put("South Carolina", "SC");
		states.put("South Dakota", "SD");
		states.put("Tennessee", "TN");
		states.put("Texas", "TX");
		states.put("Utah", "UT");
		states.put("Vermont", "VT");
		states.put("Virgin Islands", "VI");
		states.put("Virginia", "VA");
		states.put("Washington", "WA");
		states.put("West Virginia", "WV");
		states.put("Wisconsin", "WI");
		states.put("Wyoming", "WY");
		states.put("Yukon Territory", "YT");

		caseInsensitiveStates.put("Alabama".toLowerCase(), "AL");
		caseInsensitiveStates.put("Alaska".toLowerCase(), "AK");
		caseInsensitiveStates.put("Alberta".toLowerCase(), "AB");
		caseInsensitiveStates.put("American Samoa".toLowerCase(), "AS");
		caseInsensitiveStates.put("Arizona".toLowerCase(), "AZ");
		caseInsensitiveStates.put("Arkansas".toLowerCase(), "AR");
		caseInsensitiveStates.put("Armed Forces (AE)".toLowerCase(), "AE");
		caseInsensitiveStates.put("Armed Forces Americas".toLowerCase(), "AA");
		caseInsensitiveStates.put("Armed Forces Pacific".toLowerCase(), "AP");
		caseInsensitiveStates.put("British Columbia".toLowerCase(), "BC");
		caseInsensitiveStates.put("California".toLowerCase(), "CA");
		caseInsensitiveStates.put("Colorado".toLowerCase(), "CO");
		caseInsensitiveStates.put("Connecticut".toLowerCase(), "CT");
		caseInsensitiveStates.put("Delaware".toLowerCase(), "DE");
		caseInsensitiveStates.put("District Of Columbia".toLowerCase(), "DC");
		caseInsensitiveStates.put("Florida".toLowerCase(), "FL");
		caseInsensitiveStates.put("Georgia".toLowerCase(), "GA");
		caseInsensitiveStates.put("Guam".toLowerCase(), "GU");
		caseInsensitiveStates.put("Hawaii".toLowerCase(), "HI");
		caseInsensitiveStates.put("Idaho".toLowerCase(), "ID");
		caseInsensitiveStates.put("Illinois".toLowerCase(), "IL");
		caseInsensitiveStates.put("Indiana".toLowerCase(), "IN");
		caseInsensitiveStates.put("Iowa".toLowerCase(), "IA");
		caseInsensitiveStates.put("Kansas".toLowerCase(), "KS");
		caseInsensitiveStates.put("Kentucky".toLowerCase(), "KY");
		caseInsensitiveStates.put("Louisiana".toLowerCase(), "LA");
		caseInsensitiveStates.put("Maine".toLowerCase(), "ME");
		caseInsensitiveStates.put("Manitoba".toLowerCase(), "MB");
		caseInsensitiveStates.put("Maryland".toLowerCase(), "MD");
		caseInsensitiveStates.put("Massachusetts".toLowerCase(), "MA");
		caseInsensitiveStates.put("Michigan".toLowerCase(), "MI");
		caseInsensitiveStates.put("Minnesota".toLowerCase(), "MN");
		caseInsensitiveStates.put("Mississippi".toLowerCase(), "MS");
		caseInsensitiveStates.put("Missouri".toLowerCase(), "MO");
		caseInsensitiveStates.put("Montana".toLowerCase(), "MT");
		caseInsensitiveStates.put("Nebraska".toLowerCase(), "NE");
		caseInsensitiveStates.put("Nevada".toLowerCase(), "NV");
		caseInsensitiveStates.put("New Brunswick".toLowerCase(), "NB");
		caseInsensitiveStates.put("New Hampshire".toLowerCase(), "NH");
		caseInsensitiveStates.put("New Jersey".toLowerCase(), "NJ");
		caseInsensitiveStates.put("New Mexico".toLowerCase(), "NM");
		caseInsensitiveStates.put("New York".toLowerCase(), "NY");
		caseInsensitiveStates.put("Newfoundland".toLowerCase(), "NF");
		caseInsensitiveStates.put("North Carolina".toLowerCase(), "NC");
		caseInsensitiveStates.put("North Dakota".toLowerCase(), "ND");
		caseInsensitiveStates.put("Northwest Territories".toLowerCase(), "NT");
		caseInsensitiveStates.put("Nova Scotia".toLowerCase(), "NS");
		caseInsensitiveStates.put("Nunavut".toLowerCase(), "NU");
		caseInsensitiveStates.put("Ohio".toLowerCase(), "OH");
		caseInsensitiveStates.put("Oklahoma".toLowerCase(), "OK");
		caseInsensitiveStates.put("Ontario".toLowerCase(), "ON");
		caseInsensitiveStates.put("Oregon".toLowerCase(), "OR");
		caseInsensitiveStates.put("Pennsylvania".toLowerCase(), "PA");
		caseInsensitiveStates.put("Prince Edward Island".toLowerCase(), "PE");
		caseInsensitiveStates.put("Puerto Rico".toLowerCase(), "PR");
		caseInsensitiveStates.put("Quebec".toLowerCase(), "PQ");
		caseInsensitiveStates.put("Rhode Island".toLowerCase(), "RI");
		caseInsensitiveStates.put("Saskatchewan".toLowerCase(), "SK");
		caseInsensitiveStates.put("South Carolina".toLowerCase(), "SC");
		caseInsensitiveStates.put("South Dakota".toLowerCase(), "SD");
		caseInsensitiveStates.put("Tennessee".toLowerCase(), "TN");
		caseInsensitiveStates.put("Texas".toLowerCase(), "TX");
		caseInsensitiveStates.put("Utah".toLowerCase(), "UT");
		caseInsensitiveStates.put("Vermont".toLowerCase(), "VT");
		caseInsensitiveStates.put("Virgin Islands".toLowerCase(), "VI");
		caseInsensitiveStates.put("Virginia".toLowerCase(), "VA");
		caseInsensitiveStates.put("Washington".toLowerCase(), "WA");
		caseInsensitiveStates.put("West Virginia".toLowerCase(), "WV");
		caseInsensitiveStates.put("Wisconsin".toLowerCase(), "WI");
		caseInsensitiveStates.put("Wyoming".toLowerCase(), "WY");
		caseInsensitiveStates.put("Yukon Territory".toLowerCase(), "YT");
	}

	public static String convertToAbr(String fullState, boolean caseSensitive) {
		fullState = fullState.trim();

		if (caseSensitive) {
			String abbr = states.get(fullState);
			if (abbr == null)
				return null;
			else
				return abbr;
		}
		else{
			String abbr = caseInsensitiveStates.get(fullState.toLowerCase());
			if (abbr == null)
				return null;
			else
				return abbr;
		}

	}
	
	public static Boolean isAbbr(String state){
		if (caseInsensitiveStates.containsValue(state.toUpperCase()))
			return true;
		else
			return false;
	}
}
